<template>
    <div class="right-top-container">
        <div class="progress-list">
            <!-- <div class="progress-header">
                <span class="header-text">资产总数（车辆）在（在租，故障，换电，正常）：的横条图</span>
            </div>
            <div class="progress-subtitle">
                <span>其中底条表示资产总数，绿条表示各状态的数量</span>
            </div> -->
            <div class="progress-items">
                <ProgressView :progressData="progressData"></ProgressView>
                <!-- <div v-for="(item, index) in progressData" :key="index" class="progress-item">
                    <div class="item-info">
                        <span class="item-number">{{ index + 1 }}.</span>
                        <span class="item-name">{{ item.name }}</span>
                        <span class="item-value">{{ item.value }} kwh</span>
                    </div>
                    <div class="progress-bar-container">
                        <el-progress :percentage="item.percentage" :stroke-width="20" :show-text="false" color="#4ade80"
                            track-color="#374151" />
                    </div>
                </div> -->
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import ProgressView from "@/components/progressView/index.vue";
interface ProgressDataItem {
    name: string
    value: number
    valueB: number
    unit: string
    description: string
    type: number
    color: string
}

const progressData = ref<ProgressDataItem[]>([
    {
        name: '在租',
        value: 0,
        valueB: 0,
        unit: '辆',
        description: '在租总数',
        type: 1,
        color: '#1E90FF'
    },
    {
        name: '故障',
        value: 0,
        valueB: 0,
        unit: '辆',
        description: '故障总数',
        type: 1,
        color: '#FF4500'
    },
    {
        name: '换电',
        value: 0,
        valueB: 0,
        unit: '辆',
        description: '换电总数',
        type: 1,
        color: '#FFA500'
    },
    {
        name: '待租',
        value: 0,
        valueB: 0,
        unit: '辆',
        description: '待租总数',
        type: 1,
        color: '#4ade80'
    }
])


// 初始化函数
const init = (module: any) => {
    console.log('Module5 初始化完成')
    let obj = JSON.parse(module)
    if(module){
        let totalNumber = Number(obj.rent) + Number(obj.fault) + Number(obj.swap) + Number(obj.waitRent)
        progressData.value.forEach((item: any) => {
            if(item.name == '在租'){
                item.value = obj.rent
                item.valueB = totalNumber

            }else if(item.name == '故障'){
                item.value = obj.fault
                item.valueB = totalNumber
            }else if(item.name == '换电'){
                item.value = obj.swap
                item.valueB = totalNumber
            }else if(item.name == '待租'){
                item.value = obj.waitRent
                item.valueB = totalNumber
            }
        })

    }
}

// 暴露初始化函数
defineExpose({
    init
})
</script>

<style scoped lang="less">
.right-top-container {
    width: 100%;
    height: 100%;
    padding: 15px;
    box-sizing: border-box;
    background: #1e293b;
    border-radius: 8px;
}

.progress-list {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.progress-header {
    margin-bottom: 8px;

    .header-text {
        color: #e2e8f0;
        font-size: 14px;
        font-weight: 500;
        line-height: 1.4;
    }
}

.progress-subtitle {
    margin-bottom: 20px;

    span {
        color: #94a3b8;
        font-size: 12px;
        line-height: 1.4;
    }
}

.progress-items {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.progress-item {
    display: flex;
    flex-direction: column;
    gap: 8px;

    .item-info {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .item-number {
            color: #e2e8f0;
            font-size: 14px;
            font-weight: 600;
            min-width: 20px;
        }

        .item-name {
            color: #e2e8f0;
            font-size: 14px;
            flex: 1;
            margin-left: 8px;
        }

        .item-value {
            color: #e2e8f0;
            font-size: 14px;
            font-weight: 600;
        }
    }

    .progress-bar-container {
        width: 100%;

        :deep(.el-progress-bar__outer) {
            background-color: #374151 !important;
            border-radius: 10px;
        }

        :deep(.el-progress-bar__inner) {
            background: linear-gradient(90deg, #22c55e 0%, #4ade80 100%) !important;
            border-radius: 10px;
        }
    }
}
</style>